using Infrastructure.Attribute;
using Infrastructure.Extensions;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Repository;
using JTZY.Service.Business.IBusinessService;

namespace JTZY.Service.Business
{
    /// <summary>
    /// 代理商表Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(ICorecmsagentService), ServiceLifetime = LifeTime.Transient)]
    public class CorecmsagentService : BaseService<Corecmsagent>, ICorecmsagentService
    {
        /// <summary>
        /// 查询代理商表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<CorecmsagentDto> GetList(CorecmsagentQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                //.Includes(x => x.CorecmsagentgradeNav) //填充子对象
                .Where(predicate.ToExpression())
                .ToPage<Corecmsagent, CorecmsagentDto>(parm);

            return response;
        }


        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Corecmsagent GetInfo(int Id)
        {
            var response = Queryable()
                .Includes(x => x.CorecmsagentgradeNav) //填充子对象
                .Where(x => x.Id == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加代理商表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Corecmsagent AddCorecmsagent(Corecmsagent model)
        {
            return Context.InsertNav(model).Include(s1 => s1.CorecmsagentgradeNav).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改代理商表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateCorecmsagent(Corecmsagent model)
        {
            return Context.UpdateNav(model).Include(z1 => z1.CorecmsagentgradeNav).ExecuteCommand() ? 1 : 0;
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<Corecmsagent> QueryExp(CorecmsagentQueryDto parm)
        {
            var predicate = Expressionable.Create<Corecmsagent>();

            return predicate;
        }
    }
}